<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--<%@ page import="com.geping.etl.common.util.VariableUtils" %>
<%@ page import="com.geping.etl.common.entity.Sys_Auth_Role_Resource" %>
<%@ page import="com.geping.etl.common.entity.Report_Info" %>--%>
<%@ page import="com.geping.etl.common.util.VariableUtils" %>
<%
    String path = request.getContextPath();
    //当前协议+网站域名+端口号+项目名+/ ==http://localhost:8080/EastBus/
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    //数据状态
    String status = (String) request.getAttribute("action");

    VariableUtils vu = (VariableUtils) request.getSession().getAttribute("vu");
    String role = vu.getRole();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <script type="text/javascript" src="js/base-loading.js"></script>
    <link rel="stylesheet" type="text/css" href="jquery/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="jquery/themes/icon.css">
    <script type="text/javascript" src="jquery/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="jquery/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="jquery/jquery_add_tab.js"></script>
    <script type="text/javascript" src="jquery/locale/easyui-lang-zh_CN.js"></script>
    <style type="text/css">
        a {
            text-decoration: none;
        }
    </style>
</head>
<body>
<%--<table class="easyui-datagrid" fitColumns="true" title="数据管理" id="dg1"
       data-options="autoRowHeight:false,rownumbers:true,toolbar:'#tb',singleSelect:true,fit: true,url: '${serverUrl}/panel/count?panelId=${panelId}',method: 'GET'"
       style="height: 550px">
    <thead>
    <tr>
        <th data-options="field:'tableId',hidden:true"></th>
        <th data-options="field:'name',width:100,align:'center'">表单名称</th>
        &lt;%&ndash; <%
             if ("checker".equals(vu.getRoleStyle())) {
         %>
         <th data-options="field:'',width:100,align:'center'">待审核</th>
         <%
         } else {
         %>&ndash;%&gt;
        <th data-options="field:'submit',width:100,align:'center',formatter: formatSubmit">数量</th>
     &lt;%&ndash;   <th data-options="field:'check',width:100,align:'center',formatter: formatCheck">已提交</th>&ndash;%&gt;
        &lt;%&ndash; <th data-options="field:'pass',width:100,align:'center',formatter: formatPass">已审核</th>&ndash;%&gt;
        &lt;%&ndash;        <%
                    }
                %>&ndash;%&gt;
    </tr>
    </thead>
</table>--%>
<table id="dg" title="数据管理" fitColumns="true"
       data-options="rownumbers:true,toolbar:'#tb',singleSelect:true,fit: true">

</table>

<div id="tableGridToolbar">
    表名：
    <input type="text" style="width:173px;height:21px" id="queryTableNa" name="tableNa">
    表中文名:
    <input type="text" style="width:173px;height:21px" id="queryTableCn" name="tableCn">
    <a class="easyui-linkbutton" iconCls="icon-search" onclick="queryByTableCn()">查询</a>
 <%--   <a href="javascript:;" onclick="viewDetails()" class="easyui-linkbutton"
       data-options="iconCls:'icon-more',plain:true">查看详情</a>--%>
</div>

<div style="visibility: hidden;">
    <div id="viewDetailsDialog" class="easyui-dialog" data-options="iconCls:'icon-more'"
         style="width: 650px; height: 280px;top:100px;">
        <form id="viewDetailsForm" method="post">
            <table style="padding-left: 150px;padding-top:30px; padding-right: 30px">
                <tr>
                    <td align="right">表单名称：</td>
                    <td>
                        <input type="text" name="name" id="name" disabled/>
                    </td>
                </tr>
                <tr>
                    <td align="right">数量：</td>
                    <td>
                        <input type="text" name="submit" id="submit" disabled/>
                    </td>
                </tr>
                <tr>
                    <td align="right">上传频率：</td>
                    <td>
                        <input type="text" name="uploadFrequency" id="uploadFrequency" disabled/>
                    </td>
                </tr>
                <tr>
                    <td align="right">备注：</td>
                    <td>
                            <textarea name="remarks" id="remarks" rows="6" cols="30"
                                      style="vertical-align: middle;resize: none" maxlength="200" disabled></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>

<script type="text/javascript">
    function formatSubmit(value, row, index) {
        return "<a href='dataMarView?tableId=" + row.tableId + "&dataStatus=submit&panelId=${panelId}'>" + value + "</a>";
    }

    function formatCheck(value, row, index) {
        return "<a href='dataMarView?tableId=" + row.tableId + "&dataStatus=check&panelId=${panelId}'>" + value + "</a>";
    }

    /* function formatPass(value,row,index) {
          return "<a href='dataMarView?tableId=" + row.tableId +"&dataStatus=pass&panelId=${panelId}'>" + value + "</a>";
    }*/
    $(function () {
        $('#dg').datagrid({
            url: '${serverUrl}/panel/count?panelId=${panelId}',
            method: "GET",
            toolbar: "#tableGridToolbar",
            nowarp: false,
            columns: [[
                {field: 'code', title: '表名', width: 100, align: 'center'},
                {field: 'name', title: '表中文名', width: 100, align: 'center'},
                {
                    field: 'submit',
                    title: '数量',
                    width: 100,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return "<a href='dataMarView?tableId=" + row.tableId + "&dataStatus=submit&panelId=${panelId}'>" + value + "</a>";
                    }
                },
                {field: 'uploadFrequency', title: '上报频率', width: 100, align: 'center'},
                {field: 'remarks', title: '备注', width: 100, align: 'center', formatter(val) {
                        if (val){return '<span title="' + val + '">' + val + '</span>';} else {return val;}
                }},

            ]],
            loadFilter: function (data) {
                var _data = data;
                var _rows = data.rows;
                var newRows = [];
                for (var i in _rows) {
                    /*if(_rows[i].name=='测试学生'){
                        newRows.push(_rows[i]);
                    }*/
                    if (hasAuth(_rows[i])) {
                        newRows.push(_rows[i]);
                    }
                }
                data.rows = newRows;
                return data;
            }
        });

        // 关闭
        $('#viewDetailsDialog').window('close');
    });

    //var code=["code1","code2"]
    //权限判断
    var authReports =${authReports};

    function hasAuth(item) {
        for (var i in authReports) {//遍历数组
            if (authReports[i].code == item.code) {
                return true;
            }
        }
        return false;
    }

    function queryByTableCn() {
        let tableCn = $("#queryTableCn").val();
        let tableNa = $("#queryTableNa").val();
        $("#dg").datagrid("load", {tableNa: tableNa, tableCn: tableCn});
    }

    function viewDetails() {
        var rows = $("#dg").datagrid("getSelections");
        if (rows.length != 1) {
            $.messager.alert('提示', '请选择一行数据进行操作!', 'info');
            return;
        }


        let name = rows[0].name;
        let submit = rows[0].submit;
        let uploadFrequency = rows[0].uploadFrequency;
        let remarks = rows[0].remarks;

        $('#name').val(name);
        $('#submit').val(submit);
        $('#uploadFrequency').val(uploadFrequency);
        $('#remarks').val(remarks);


        //最后打开窗口
        $("#viewDetailsDialog").window({title: "查看详情"});
        $('#viewDetailsDialog').window('open');
        $('#viewDetailsDialog').window({modal: true});
    }
</script>
</body>
</html>
